var objUrl;
var img_html;
/**
 * 个人图像上传时显示
 */
$(function() {
	$("#picture").change(function() {
			var img_div = $(".img_div");
			var filepath = $("#picture").val();
			objUrl = getObjectURL(this.files[0]);
			img_html = "<div class='isImg'><img src='"
			+ objUrl
			+ "' style='height: 220px; width:220px;border-radius:50%;' /></div>";
			img_div.empty();
			img_div.append(img_html);
		});
	
	show();
});

/**
 * 图书上传封面显示
 */
function show(){
	$("#img").change(function() {
				var sibTr = $("#showImg")
				objUrl = getObjectURL(this.files[0]);
				var img_html = "<tr id=\"addTr\"><td  colspan=\"2\"  align=\"center\"><div class='isImg'><img src='"+ objUrl
					+ "' style='height: 140px; width:140px;' /></div></tr>";
				sibTr.after(img_html);
				img_html.empty();
			});
	
}


function getObjectURL(file) {
	var url = null;
	if(window.createObjectURL != undefined) { // basic
		url = window.createObjectURL(file);
	} else if(window.URL != undefined) { // mozilla(firefox)
		url = window.URL.createObjectURL(file);
	} else if(window.webkitURL != undefined) { // webkit or chrome
		url = window.webkitURL.createObjectURL(file);
	}
	return url;
}

/**
 * 弹出上传框
 */
function showDiv(){
		document.getElementById("popDiv").style.display='block';
		document.getElementById("bg").style.display='block';
}
	/**
	*关闭弹出层
	*/
function cancel(){
		document.getElementById("popDiv").style.display='none';
		document.getElementById("bg").style.display='none';
}
	/**
	 * 上传保存
	 **/
function save(){
		var picture = $('#picture').val();
		var suffix = picture.substring(picture.lastIndexOf('.')+1,picture.length);
		if(picture == ''){
			alert('请选择要上传的图片，不能为空!');
			return;
		}else if(suffix != 'png' && suffix != 'jpg' && suffix !='gif'){
			alert('只能是png/jpg/gif格式的!');
			return;
		}else{
			document.getElementById("popDiv").style.display='none';
			document.getElementById("bg").style.display='none';
			document.getElementById("image").onsubmit();
		}
}